<?php

namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class YuansusysController extends AdminbaseController {
    public function index() {
 
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        $queryDesc='order by id';
        
        $postData=array();
        $where='';
        $postData['p']=$p;

        $Model = M();
        $query=$Model->query("SELECT count(id) as count FROM `z_game` ".$where."  ");
        $count=$query[0]['count'];
        $page = $this->page($count, 10, $p);
        $uInfo=$Model->query("SELECT * FROM `z_game` ".$where."  ".$queryDesc." limit ".(($p-1)*10).",10 ");
        $theData=array();
         
        foreach ($uInfo as $v){
            $theData[]=array(
                'id'=>$v['id'],
                'name'=>$v['name'],
                'game_bg'=>$v['game_bg'],
                'zaitu'=>json_decode($v['zhangai_tu'],true),
                'jbitu'=>json_decode($v['jinbi_tu'],true),
            );
           
        }
        $this->assign("postData", $postData);
        $this->assign("page", $page->show('Admin'));
        $this->assign("thedata", $theData);

        $this->display();
    }
    
    public function add() {
        
        
        $this->display();
    }
    
   
    
    public function delete() {
        if (isset($_GET['id']) && !empty($_GET['id'])){
            $Model = M("game", 'z_');
            $data=array();
            if ($Model->delete($_GET['id'])!==false) {
                $this->success("删除成功！");
            } else {
                $this->error("删除失败！");
            } 
        }
    }
    
    public function editbipost() {
        
        if (isset($_POST['zai1']) && isset($_POST['option_id'])){
            $Model = M("game", 'z_');
            $data=array();
            
            $zaTuArr=array();
            if (isset($_POST['zai1']) && !empty($_POST['zai1'])){
                $zaTuArr[]=$_POST['zai1'];
            }
            if (isset($_POST['zai2']) && !empty($_POST['zai2'])){
                $zaTuArr[]=$_POST['zai2'];
            }
            if (isset($_POST['zai3']) && !empty($_POST['zai3'])){
                $zaTuArr[]=$_POST['zai3'];
            }
            if (isset($_POST['zai4']) && !empty($_POST['zai4'])){
                $zaTuArr[]=$_POST['zai4'];
            }
            if (isset($_POST['zai5']) && !empty($_POST['zai5'])){
                $zaTuArr[]=$_POST['zai5'];
            }
            if (isset($_POST['zai6']) && !empty($_POST['zai6'])){
                $zaTuArr[]=$_POST['zai6'];
            }
            if (isset($_POST['zai7']) && !empty($_POST['zai7'])){
                $zaTuArr[]=$_POST['zai7'];
            }
            if (isset($_POST['zai8']) && !empty($_POST['zai8'])){
                $zaTuArr[]=$_POST['zai8'];
            }
            $data['jinbi_tu'] =json_encode($zaTuArr);
            $id=$_POST['option_id'];
            $status=$Model->where('id='.$id)->save($data);
            
            $sql=$Model->getLastSql();
            
            
            $info=json_encode(array('status'=>'yes'));
            echo $info;
        }
    }
    
    public function biedit() {
        if (isset($_GET['id'])){
            $id=$_GET['id'];
        }else{
            exit;
        }
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        $Model = M();
        $thedata=$Model->query("SELECT * FROM `z_game` where id='".$id."' limit 0,1  ");
        
        $getData=$thedata[0];
        $getData['zaiArr']=json_decode($getData['jinbi_tu'],true);

        $this->assign("p", $p);
        $this->assign("thedata", $getData);
        
        $this->display();
    }
  
    public function edit() {
        if (isset($_GET['id'])){
            $id=$_GET['id'];
        }else{
            exit;
        }
        $p=1;
        if (isset($_GET['p'])){
            $p=$_GET['p'];
        }
        $Model = M();
        $thedata=$Model->query("SELECT * FROM `z_game` where id='".$id."' limit 0,1  ");
        
        $getData=$thedata[0];
        $getData['zaiArr']=json_decode($getData['zhangai_tu'],true);
        
        $getData['ztArr']=json_decode($getData['zhangai_txt'],true);
        

        $this->assign("p", $p);
        $this->assign("thedata", $getData);
         
        $this->display();
    }
     
     
    public function editpost() {
 
        if (isset($_POST['zai1']) && isset($_POST['option_id'])){
            $Model = M("game", 'z_');
            $data=array();
            
            $zaTuArr=array();
            if (isset($_POST['zai1']) && !empty($_POST['zai1'])){
                $zaTuArr[]=$_POST['zai1'];
            }
            if (isset($_POST['zai2']) && !empty($_POST['zai2'])){
                $zaTuArr[]=$_POST['zai2'];
            }
            if (isset($_POST['zai3']) && !empty($_POST['zai3'])){
                $zaTuArr[]=$_POST['zai3'];
            }
            if (isset($_POST['zai4']) && !empty($_POST['zai4'])){
                $zaTuArr[]=$_POST['zai4'];
            }
            if (isset($_POST['zai5']) && !empty($_POST['zai5'])){
                $zaTuArr[]=$_POST['zai5'];
            }
            if (isset($_POST['zai6']) && !empty($_POST['zai6'])){
                $zaTuArr[]=$_POST['zai6'];
            }
            if (isset($_POST['zai7']) && !empty($_POST['zai7'])){
                $zaTuArr[]=$_POST['zai7'];
            }
            if (isset($_POST['zai8']) && !empty($_POST['zai8'])){
                $zaTuArr[]=$_POST['zai8'];
            }
            
            $zaTxtAr=array();
            if (isset($_POST['zta1']) && !empty($_POST['zta1'])){
                $zaTxtAr[]= array('a'=>$_POST['zta1'],
                    'b'=>$_POST['ztb1'],'c'=>$_POST['ztc1']);
            }
            if (isset($_POST['zta2']) && !empty($_POST['zta2'])){
                $zaTxtAr[]= array('a'=>$_POST['zta2'],
                    'b'=>$_POST['ztb2'],'c'=>$_POST['ztc2']);
            }
            if (isset($_POST['zta3']) && !empty($_POST['zta3'])){
                $zaTxtAr[]= array('a'=>$_POST['zta3'],
                    'b'=>$_POST['ztb3'],'c'=>$_POST['ztc3']);
            }
            if (isset($_POST['zta4']) && !empty($_POST['zta4'])){
                $zaTxtAr[]= array('a'=>$_POST['zta4'],
                    'b'=>$_POST['ztb4'],'c'=>$_POST['ztc4']);
            }
            if (isset($_POST['zta5']) && !empty($_POST['zta5'])){
                $zaTxtAr[]= array('a'=>$_POST['zta5'],
                    'b'=>$_POST['ztb5'],'c'=>$_POST['ztc5']);
            }
            if (isset($_POST['zta6']) && !empty($_POST['zta6'])){
                $zaTxtAr[]= array('a'=>$_POST['zta6'],
                    'b'=>$_POST['ztb6'],'c'=>$_POST['ztc6']);
            }
            if (isset($_POST['zta7']) && !empty($_POST['zta7'])){
                $zaTxtAr[]= array('a'=>$_POST['zta7'],
                    'b'=>$_POST['ztb7'],'c'=>$_POST['ztc7']);
            }
            if (isset($_POST['zta8']) && !empty($_POST['zta8'])){
                $zaTxtAr[]= array('a'=>$_POST['zta8'],
                    'b'=>$_POST['ztb8'],'c'=>$_POST['ztc8']);
            }

            $data['zhangai_txt'] =json_encode($zaTxtAr);
            $data['zhangai_tu'] =json_encode($zaTuArr);
            $id=$_POST['option_id'];
            $status=$Model->where('id='.$id)->save($data);
 
            $sql=$Model->getLastSql();
            
            
            $info=json_encode(array('status'=>'yes'));
            echo $info;
        }
    }
 
}
